<%@ tag pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="promotion" uri="http://com.primus.promotion/tag/core" %>
<%@ taglib prefix="pbase" tagdir="/WEB-INF/tags/base" %>
<%@ attribute name="promotionId" required="true" type="java.lang.Long" %>
<pbase:row layout="single">
    <label class="col-sm-2 control-label no-padding-right">设置中奖订单数</label>
    <div class="col-sm-10 form-group">
        <div class="col-xs-12">
            <div class="row col-xs-12"><span id="_icon_plus_order_seq" class="label"><i
                    class="ace-icon glyphicon glyphicon-plus"></i></span></div>
            <div class="row col-xs-12">
                <table id="_lucky_order_seq_table" class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>订单数量</th>
                        <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</pbase:row>

<script>
    $(function () {
        var $table_body = $('#_lucky_order_seq_table').find('tbody');
        <c:if test="${promotionId != null && promotionId > 0}">
        $.ajax({
            cache: true,
            async: false,
            url: 'management/luckyOrderPromotion/luckyOrderSeq.do?id=${promotionId}',
            type: 'get',
            dataType: 'json'
        }).success(function (data) {
            var append_html = [];
            for (var d in data) {
                append_html.push('<tr>');
                append_html.push('<td class="value"><input type="number" value="' + data[d] + '"/></td>');
                append_html.push('<td><span class="btn btn-xs btn-info order_seq_remove"><i class="ace-icon glyphicon glyphicon-remove"></i></span></td>')
                append_html.push('</tr>');
            }
            $table_body.append(append_html.join("\n"));
        });
        </c:if>

        $('#_icon_plus_order_seq').click(function () {
            var append_html = [];
            append_html.push('<tr>');
            append_html.push('<td class="value"><input type="number" /></td>');
            append_html.push('<td><span class="btn btn-xs btn-info order_seq_remove"><i class="ace-icon glyphicon glyphicon-remove"></i></span></td>')
            append_html.push('</tr>');
            $table_body.append(append_html.join("\n"));
        });

        $table_body.on('click', '.order_seq_remove', function () {
            $(this).parents("tr").remove();
        });
    });
</script>
